package com.junxonline.instant.admin.controller.device;

import com.junxonline.instant.dao.entity.vo.common.IdsVO;
import com.junxonline.instant.dao.entity.vo.device.command.*;
import com.junxonline.instant.admin.service.device.CommandService;
import com.junxonline.instant.common.annotation.DeviceOperationLog;
import com.junxonline.instant.common.annotation.OperationLog;
import com.junxonline.instant.common.entity.common.CommonResult;
import com.junxonline.instant.common.enumeration.AdminErrorEnum;
import com.junxonline.instant.common.enumeration.OperationEnum;
import lombok.extern.log4j.Log4j2;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 终端指令Controller
 *
 * @author JunX
 * @date 2021-10-22
 */
@Log4j2
@RestController
@RequestMapping(value = "/device/command")
public class CommandController {

    @Autowired
    private CommandService commandService;

    /**
     * 设置音量
     *
     * @param vo 请求参数
     * @return CommonResult
     */
    @RequiresPermissions(value = "device:terminal:send")
    @OperationLog(label = "终端指令-设置音量", type = OperationEnum.COMMAND)
    @DeviceOperationLog(label = "设置音量", type = OperationEnum.EDIT)
    @PostMapping(value = "/setVolume")
    public CommonResult setVolume(@RequestBody(required = false) SetVolumeVO vo) {
        if (vo == null || vo.getIds() == null || vo.getIds().size() <= 0 || vo.getVolume() == null) {
            return CommonResult.fail(AdminErrorEnum.PARAMS_IS_NULL);
        }
        commandService.setVolume(vo);
        return CommonResult.success();
    }

    /**
     * 设置显示方式
     *
     * @param vo 请求参数
     * @return CommonResult
     */
    @RequiresPermissions(value = "device:terminal:send")
    @OperationLog(label = "终端指令-设置显示方式", type = OperationEnum.COMMAND)
    @DeviceOperationLog(label = "设置显示方式", type = OperationEnum.EDIT)
    @PostMapping(value = "/setDisplayType")
    public CommonResult setDisplayType(@RequestBody(required = false) SetDisplayTypeVO vo) {
        if (vo == null || vo.getIds() == null || vo.getIds().size() <= 0 || vo.getDisplayType() == null) {
            return CommonResult.fail(AdminErrorEnum.PARAMS_IS_NULL);
        }
        commandService.setDisplayType(vo);
        return CommonResult.success();
    }

    /**
     * 拉取音量
     *
     * @param vo 请求参数
     * @return CommonResult
     */
    @RequiresPermissions(value = "device:terminal:send")
    @OperationLog(label = "终端指令-拉取音量", type = OperationEnum.COMMAND)
    @DeviceOperationLog(label = "拉取音量", type = OperationEnum.QUERY)
    @PostMapping(value = "/queryVolume")
    public CommonResult queryVolume(@RequestBody(required = false) IdsVO<List<Long>> vo) {
        if (vo == null || vo.getIds() == null || vo.getIds().size() <= 0) {
            return CommonResult.fail(AdminErrorEnum.PARAMS_IS_NULL);
        }
        // 选择的终端数量小于1则发送消息
        if (vo.getIds().size() <= 1) {
            commandService.queryVolume(vo);
        }
        return CommonResult.success();
    }

    /**
     * 拉取显示方式
     *
     * @param vo 请求参数
     * @return CommonResult
     */
    @RequiresPermissions(value = "device:terminal:send")
    @OperationLog(label = "终端指令-拉取显示方式", type = OperationEnum.COMMAND)
    @DeviceOperationLog(label = "拉取显示方式", type = OperationEnum.QUERY)
    @PostMapping(value = "/queryDisplayType")
    public CommonResult queryDisplayType(@RequestBody(required = false) IdsVO<List<Long>> vo) {
        if (vo == null || vo.getIds() == null || vo.getIds().size() <= 0) {
            return CommonResult.fail(AdminErrorEnum.PARAMS_IS_NULL);
        }
        // 选择的终端数量小于1则发送消息
        if (vo.getIds().size() <= 1) {
            commandService.queryDisplayType(vo);
        }
        return CommonResult.success();
    }

    /**
     * 拉取终端截屏
     *
     * @param vo 请求参数
     * @return CommonResult
     */
    @RequiresPermissions(value = "device:terminal:send")
    @OperationLog(label = "终端指令-拉取终端截屏", type = OperationEnum.COMMAND)
    @DeviceOperationLog(label = "拉取终端截屏", type = OperationEnum.QUERY)
    @PostMapping(value = "/pullScreenshot")
    public CommonResult pullScreenshot(@RequestBody(required = false) IdsVO<List<Long>> vo) {
        if (vo == null || vo.getIds() == null || vo.getIds().size() <= 0) {
            return CommonResult.fail(AdminErrorEnum.PARAMS_IS_NULL);
        }
        commandService.pullScreenshot(vo);
        return CommonResult.success();
    }

}
